const Express = require('express');
const router = Express.Router();
const articles = require('../articles');

router.get('/:articleId', function (req, res) {
    if (req.params.articleId) {
        const result = articles.data.find(article => article.item_id === req.params.articleId);
        if (result) {
            res.render('single', {article: result});
        } else {
            res.send('no article');
        }
    } else {
        res.send('no article');
    }
});

router.get('/', function (req, res,) {
    res.render('single', {article: {}});
});

module.exports = router;